package cn.school.mybatis.servlet;

import cn.school.mybatis.pojo.Admin;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/doLoginWelcomeServlet")
public class doLoginWelcomeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

        HttpSession sess=request.getSession();
        Admin admin = (Admin) sess.getAttribute("USER_LOGIN");
        if (admin == null) {
            out.println("<script>alert('请登录账号！');location.replace('"+request.getContextPath()+"/AdminLTEdemo01/s_login/login.jsp')</script>");
        }else {

            out.println("<script>alert('"+admin.getUsername()+"欢迎您！');");
            request.getRequestDispatcher("/WEB-INF/AdminLTEdemo01/home.jsp").forward(request,response);

        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
